package mylittleinvestigations;

import mylittleinvestigations.CaseInformation.CaseXmlWriter;
import mylittleinvestigations.CaseInformation.Case;
import mylittleinvestigations.CaseInformation.CaseXmlReader;
import java.io.IOException;

public class Evidence
{
    private String smallTextureId;
    private String largeTextureId;

    private Sprite smallSprite;
    private Sprite largeSprite;

    public Evidence(String smallTextureId, String largeTextureId, String name, String description, boolean isProfile)
    {
        this.smallTextureId = smallTextureId;
        this.largeTextureId = largeTextureId;
        this.name = name;
        this.description = description;
        this.isProfile = isProfile;
        this.isEnabled = false;
        this.isHidden = false;
    }

    public Sprite getSmallSprite()
    {
        if (this.smallSprite == null)
        {
            this.smallSprite = Case.getInstance().getSpriteManager().GetSpriteFromId(this.smallTextureId);
        }

        return this.smallSprite;
    }

    public Sprite getLargeSprite()
    {
        if (this.largeSprite == null)
        {
            this.largeSprite = Case.getInstance().getSpriteManager().GetSpriteFromId(this.largeTextureId);
        }

        return this.largeSprite;
    }
    
    private String name;

    public String getName() { return this.name; }
    private void setName(String name) { this.name = name; }
    
    private String description;

    public String getDescription() { return this.description; }
    private void setDescription(String description) { this.description = description; }
    
    private boolean isProfile;
    
    public boolean getIsProfile() { return this.isProfile; }
    public void setIsProfile(boolean isProfile) { this.isProfile = isProfile; }
    
    private boolean isEnabled;
    
    public boolean getIsEnabled() { return this.isEnabled; }
    public void setIsEnabled(boolean isEnabled) { this.isEnabled = isEnabled; }
    
    private boolean isHidden;
    
    public boolean getIsHidden() { return this.isHidden; }
    public void setIsHidden(boolean isHidden) { this.isHidden = isHidden; }

    public void SaveToXml(CaseXmlWriter writer) throws IOException
    {
        writer.StartElement("Evidence");
        writer.WriteSpriteId("SmallSpriteId", this.smallTextureId);
        writer.WriteSpriteId("LargeSpriteId", this.largeTextureId);
        writer.WriteTextElement("Name", this.name);
        writer.WriteTextElement("Description", this.description);
        writer.WriteBooleanElement("IsProfile", this.isProfile);
        writer.WriteBooleanElement("IsEnabled", this.isEnabled);
        writer.WriteBooleanElement("IsHidden", this.isHidden);
        writer.EndElement();
    }

    public Evidence(CaseXmlReader reader)
    {
        reader.StartElement("Evidence");
        this.smallTextureId = reader.ReadTextElement("SmallSpriteId");
        this.largeTextureId = reader.ReadTextElement("LargeSpriteId");
        this.name = reader.ReadTextElement("Name");
        this.description = reader.ReadTextElement("Description");
        this.isProfile = reader.ReadBooleanElement("IsProfile");
        this.isEnabled = reader.ReadBooleanElement("IsEnabled");
        this.isHidden = reader.ReadBooleanElement("IsHidden");
        reader.EndElement();
    }

    public void markChildSprites(String parentMark)
    {
        this.getSmallSprite().markChildSprites(parentMark);
        this.getLargeSprite().markChildSprites(parentMark);
    }
}
